home *** CD-ROM | disk | FTP | other *** search
- Path: telepost.no!usenet
- From: Carsten Arnholm <ca@sesam.dnv.no>
- Newsgroups: comp.lang.c++
- Subject: Re: question assignment operator in c++
- Date: 7 Mar 1996 13:17:03 GMT
- Organization: DNV
- Message-ID: <4hmnkf$t1s@nms.telepost.no>
- References: <menghua_wang.1.002DB7BE@muccmail.missouri.edu> <4hl7i7$81a@clarknet.clark.net>
- NNTP-Posting-Host: hugin.sesam.dnv.no
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1 (Windows; I; 32bit)
-
- gusty@clark.net (Harlan Messinger) wrote:
- >menghua wang (menghua_wang@muccmail.missouri.edu) wrote:
- >: I do not why the assignment operator can only be overloaded as a member
- >: function in a class such as:
- >:
- >: class myclass {
- >: int i;
- >: public:
- >: myclass operator= (myclass &A) {
- >: i = A.i;
- >: return *this;
- >: }
- >: };
- >:
- >: Why does not the following frind overloading work?
- >:
- >: mycalss operator= (myclass &A, myclass &B) {
- >: A.i = B.i;
- >: return A;
- >: }
- >
- >I believe it's because each class has a default assignment operator as an
- >implicit member function. Therefore, if you want to write your own, you
- >have to overload the existing implied one, which calls for an explicit
- >member function. That, or perhaps there would be inheritance problems.
- >
-
-
- I'm more inclined to believe the reason is that you are not supposed to
- redefine behaviour of assignment to basic types such as int, float .. etc.
- which would occur if you were allowed to overload the global assignment.
-
- Carsten Arnholm
-
-